# /usr/bin/python3

# Author: 爱编程的章老师
# @Time: 2021/1/2 0002
# E-mail: Bluesand2010@163.com
import sys
import pygame
from math import pi

def homework():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    screen.fill((255, 255, 255))

    # 画正方形
    rect = (300,200,200,200)
    pygame.draw.rect(screen, (0,0,255), rect,5)

    # 画上侧的弧
    rect = (300, 100, 200, 200)
    pygame.draw.arc(screen, (0,255,0), rect, pi, 2*pi, width=5)

    # 画下侧的弧
    rect = (300, 300, 200, 200)
    pygame.draw.arc(screen, (0, 255, 0), rect, 0, pi, width=5)

    # 画左侧的弧
    rect = (200, 200, 200, 200)
    pygame.draw.arc(screen, (0, 255, 0), rect, - pi/2, pi/2, width=5)
    # 画右侧弧
    rect = (400, 200, 200, 200)
    pygame.draw.arc(screen, (0, 255, 0), rect, pi / 2, -pi / 2, width=5)

    pygame.display.update()

    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()

    pygame.quit()

# 画线段
def draw_line():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    screen.fill((255, 255, 255))

    start_pos = 400, 300
    end_pos = 300, 200
    RED = (255, 0, 0)
    pygame.draw.line(screen, RED, start_pos, end_pos, 5)

    pygame.display.update()

    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
    pygame.quit()


# 画折线
def draw_lines():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    screen.fill((255, 255, 255))

    p_list = [(400, 300), (400, 200), (500, 200), (500, 400)]  # 定义各个折点的坐标
    RED = (255, 0, 0)  # 定义红色
    pygame.draw.lines(screen, RED, True, p_list, 10)  # 画封闭的图
    pygame.display.update()  # 更新屏幕

    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
    pygame.quit()


def draw_balance():
    pygame.init()
    screen = pygame.display.set_mode((800, 600))
    screen.fill((255, 255, 255))

    RED = (255, 0, 0)  # 定义红色

    # 底座三角形三个点
    triangle_list = [(400, 300), (350, 350), (450, 350)]
    pygame.draw.polygon(screen, RED, triangle_list)


    # 秤杆
    start_pos = 150, 275
    end_pos = 700, 325
    # pygame.draw.line(screen, RED, start_pos, end_pos, 3)
    pygame.draw.aaline(screen, RED, start_pos, end_pos, 3)

    # 画重物
    # 左边放一个正方形,右边放一个圆, 因为秤杆是斜的,所以正方形不能直接用rect来画.选择用多边形来画

    # 定义蓝色
    BLUE = (0, 0, 255)
    rect_list = [(150, 275),(200, 280), (208,230), (158, 225)]
    pygame.draw.polygon(screen, BLUE, rect_list)

    circle_center = 680, 300
    r = 22
    pygame.draw.circle(screen, BLUE, circle_center, r)

    pygame.display.update()  # 更新屏幕
    while 1:
        for event in pygame.event.get():
            if event.type == pygame.QUIT:
                sys.exit()
    pygame.quit()

if __name__ == '__main__':
    draw_balance()